package com.sx.zongzhi.presenter;

import android.content.Context;

import com.sx.zongzhi.modle.CollectManager;
import com.sx.zongzhi.modle.HeadParamBean;
import com.sx.zongzhi.net.BaseCallBack;
import com.sx.zongzhi.net.BaseResult;
import com.sx.zongzhi.utils.BaseUtil;
import com.sx.zongzhi.view.CommentView;

import java.util.Map;

/**添加房屋
 * Created by admin on 2017/12/18.
 */

public class AddFactHousePest {
    CommentView commentView;

    public AddFactHousePest(CommentView commentView) {
        this.commentView = commentView;
    }

    /**
     houseInfo.addressType.id	是	string	房屋地址类型(通过根据字典项名称获取数据字典接口获取对应字典项数组，domainName=现居住址类型)
     houseInfo.community	是	string	小区(房屋地址类型选择商品房时必填)
     houseInfo.block	是	string	幢(房屋地址类型选择商品房时必填)
     houseInfo.unit	是	string	单位(房屋地址类型选择商品房时必填)
     houseInfo.room	是	string	室(房屋地址类型选择商品房时必填)
     houseInfo.address	是	string	住房地址(房屋地址类型选择其他时必填)
     houseInfo.houseUses.id	否	string	建筑用途
     houseInfo.houseArea	否	string	建筑面积
     houseInfo.certificateType.id	是	string	证件代码(通过根据字典项名称获取数据字典接口获取对应字典项数组，domainName=证件代码)
     houseInfo.certificateNumbe	是	string	证件号码
     houseInfo.name	是	string	房主姓名
     houseInfo.propertyPersonMobile	是	string	手机号码
     houseInfo.propertyPersonTel	是	string	电话号码
     houseInfo.nowLiveAddress	是	string	房主现居详址
     houseInfo.isRentalHouse	是	boolean	是否出租房
     */

    public void addFactHouse(Context context,String orgId,String addressTypeId, String address, String community, String block,
                             String unit, String room, String houseUsesId, String houseArea,
                             String certificateTypeId, String certificateNumbe, String name,
                             String propertyPersonMobile, String propertyPersonTel,
                             String nowLiveAddress, boolean isRentalHouse,String urlPath) {
        Map<String,Object> map = HeadParamBean.getHead(context);
        map.put("houseInfo.organization.id",orgId);
        map.put("houseInfo.addressType.id",addressTypeId);
        if (!BaseUtil.isEmpty(address)){
            map.put("houseInfo.address",address);
        }else {
            map.put("houseInfo.community",community);
            map.put("houseInfo.block",block);
            map.put("houseInfo.unit",unit);
            map.put("houseInfo.room",room);
        }
        map.put("houseInfo.houseUses.id",houseUsesId);
        map.put("houseInfo.houseArea",houseArea);
        map.put("houseInfo.certificateType.id",certificateTypeId);
        map.put("houseInfo.certificateNumbe",certificateNumbe);
        map.put("houseInfo.name",name);
        if (!BaseUtil.isEmpty(propertyPersonMobile)){
            map.put("houseInfo.propertyPersonMobile",propertyPersonMobile);
        }else {
            map.put("houseInfo.propertyPersonTel",propertyPersonTel);
        }
        map.put("houseInfo.nowLiveAddress",nowLiveAddress);
        map.put("houseInfo.isRentalHouse",isRentalHouse);
        if(!BaseUtil.isEmpty(urlPath)){
            map.put("houseInfo.fileStorage.path",urlPath);
        }
        new CollectManager().addFactHouse(map, new BaseCallBack<BaseResult<Boolean>>() {
            @Override
            public void onSuccess(BaseResult<Boolean> response) {
                commentView.commentSuccess(response.data);
            }

            @Override
            public void onFailures(String message) {
                commentView.showError(message);
            }
        });
    }
    /**
     houseInfo.addressType.id	是	string	房屋地址类型(通过根据字典项名称获取数据字典接口获取对应字典项数组，domainName=现居住址类型)
     houseInfo.community	是	string	小区(房屋地址类型选择商品房时必填)
     houseInfo.block	是	string	幢(房屋地址类型选择商品房时必填)
     houseInfo.unit	是	string	单位(房屋地址类型选择商品房时必填)
     houseInfo.room	是	string	室(房屋地址类型选择商品房时必填)
     houseInfo.address	是	string	住房地址(房屋地址类型选择其他时必填)
     houseInfo.houseUses.id	否	string	建筑用途
     houseInfo.houseArea	否	string	建筑面积
     houseInfo.certificateType.id	是	string	证件代码(通过根据字典项名称获取数据字典接口获取对应字典项数组，domainName=证件代码)
     houseInfo.certificateNumbe	是	string	证件号码
     houseInfo.name	是	string	房主姓名
     houseInfo.propertyPersonMobile	是	string	手机号码
     houseInfo.propertyPersonTel	是	string	电话号码
     houseInfo.nowLiveAddress	是	string	房主现居详址
     houseInfo.isRentalHouse	是	boolean	是否出租房
     */

    public void updateFactHouse(Context context,String id,String addressTypeId, String address, String community, String block,
                             String unit, String room, String houseUsesId, String houseArea,
                             String certificateTypeId, String certificateNumbe, String name,
                             String propertyPersonMobile, String propertyPersonTel,
                             String nowLiveAddress, boolean isRentalHouse,String urlPath) {
        Map<String,Object> map = HeadParamBean.getHead(context);
        map.put("houseInfo.id",id);
        map.put("houseInfo.addressType.id",addressTypeId);
        if (!BaseUtil.isEmpty(address)){
            map.put("houseInfo.address",address);
        }else {
            map.put("houseInfo.community",community);
            map.put("houseInfo.block",block);
            map.put("houseInfo.unit",unit);
            map.put("houseInfo.room",room);
        }
        map.put("houseInfo.houseUses.id",houseUsesId);
        map.put("houseInfo.houseArea",houseArea);
        map.put("houseInfo.certificateType.id",certificateTypeId);
        map.put("houseInfo.certificateNumbe",certificateNumbe);
        map.put("houseInfo.name",name);
        if (!BaseUtil.isEmpty(propertyPersonMobile)){
            map.put("houseInfo.propertyPersonMobile",propertyPersonMobile);
        }else {
            map.put("houseInfo.propertyPersonTel",propertyPersonTel);
        }
        map.put("houseInfo.nowLiveAddress",nowLiveAddress);
        map.put("houseInfo.isRentalHouse",isRentalHouse);
        if(!BaseUtil.isEmpty(urlPath)){
            map.put("houseInfo.fileStorage.path",urlPath);
        }
        new CollectManager().updateFactHouse(map, new BaseCallBack<BaseResult<Boolean>>() {
            @Override
            public void onSuccess(BaseResult<Boolean> response) {
                commentView.commentSuccess(response.data);
            }

            @Override
            public void onFailures(String message) {
                commentView.showError(message);
            }
        });
    }
}
